<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>销售商品</title>
</head>
<style>
#flex div{
	height:45px;
	line-height:36px;
}
</style>
<body>

<div class="container">

    <div class="comm_content">
            <div class="search-box">
                <div style="position:relative">
                    <form id="search_form" onsubmit="return false;" class="form-inline">
                        <table>
                            <tbody>
                                <tr>
                                    <td>
                                        <span style="margin-left:25px;">
	                                        城市：
	                                        <select name="cityID" id="cityID" class="form-control">
	                                            <option value="0">请选择</option>
	                                            <!--{foreach from=$city item=c}-->
													<option value="<!--{$c.id}-->"><!--{$c.name}--></option>
												<!--{/foreach}-->
	                                        </select>
	                                    </span>

	                                    <span>
	                                        商品类目 ：
	                                        <select name="bigCategoryID" id="bigCategoryID" class="form-control">
	                                            <option value="0">请选择</option>
	                                            <!--{foreach from=$category item=g}-->
													<option value="<!--{$g.bigCategoryID}-->"><!--{$g.name}--></option>
												<!--{/foreach}-->
	                                        </select>
	                                    </span>

	                                    <span>
				                        	商品款号：
				                        	<input type="text" class="form-control" id="product_code" name="product_code" style="width:249px;">
				                        </span>
				                        <br/>
				                        <span>
				                        	商品名称：
				                        	<input type="text" class="form-control w300" id="goodsName" name="goodsName">
				                        </span>

				                        <span>
	                                        上下架状态 ：
	                                        <select name="useFlg" id="useFlg" class="form-control">
	                                            <option value="all">请选择</option>
	                                            <option value="1">上架</option>
	                                            <option value="0">下架</option>
	                                        </select>
	                                    </span>

                                        <span><input type="button" value="查询" class="btn btn-primary" onclick="goods.search();" /></span>
                                        <span><input type="button" value="重置" class="btn btn-warning" onclick="goods.clear();" /></span>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>

            <table id="flex" style="display:none"></table>

        </div>

</div>

<script type="text/javascript">
    $("#flex").flexigrid({
        url:"/invokingAjax-backend/goods/goodsSale.ajax?operFlg=1&xjx=none",
        dataType: "json",
        colModel : [
	        {display: "操作", width : 220, align: "center"},
	        {display: "款号", width : 90},
	        {display: "商品名称",width : 380},
	        {display: "城市",width : 90},
	        {display: "类目", width : 180},
	        {display: "首页分类排序", width : 90 }
        ],
        sortname: "cityID",
        sortorder: "asc",
        usepager: true,
        rp: 20,
        useRp: true,
        showTableToggleBtn: true
    });

    var goods = {

        postID_str  : "" ,

        do_flg 	    : 0  ,

		allFlg		: 0 ,

        //商品列表
        search: function() {
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({newp: 1,params: dt}).flexReload();
        },

        load: function() {
            $("#flex").flexReload();
        },

        toSale: function() {
			this.do_flg	    = 3 ;
			this.postID_str = "";
            $.each($("#flex").find("tr"), function(k, v) {
                if ($(v).hasClass("trSelected")) {
                    goods.postID_str += "_" + $(v).attr("id").replace("row", "");
                }
            });

            if (this.postID_str == ""){
                E.alert("请选择要同步的商品");
                return false ;
            }

           	E.confirm("您确认要同步选中的商品吗？", "goods.doConfirm");
        },

        //上架确认
        doConfirm : function () {
        	E.loadding.open();
        	if(this.do_flg == 3)
        		var usrlink = "/invokingAjax-backend/goods/goodsSale.ajax?operFlg=9&postID_str=" + goods.postID_str  ;
        	else
        		var usrlink = "/invokingAjax-backend/goods/goodsSale.ajax?operFlg=8&postID_str=" + goods.postID_str + "&forsale=" + this.do_flg ;

            $.ajax({
                type: "POST",
                url: usrlink ,
                dataType: "JSON",
                success: function( result_obj ) {
                    if (result_obj.code == 200) {
                    	goods.allFlg = 0 ;
                        E.alert(result_obj.message, 2, "goods.load");
                        E.loadding.close();
                    } else {
                        E.alert(result_obj.message);
                    }
                }
            });

        },

        //全选
        selectAll : function () {
        	if(goods.allFlg == 0){
        		$("[id ^='row']").addClass("trSelected");
        		goods.allFlg = 1 ;
        	}else{
        		$("[id ^='row']").removeClass("trSelected");
        		goods.allFlg = 0 ;
        	}
        },

        //重置
        clear: function(){
        	$("#product_code").val('');
	        $("#goodsName").val('');
	        $("#cityID").val('0');
	        $("#bigCategoryID").val('0');
	        $("#useFlg").val('all');
        },

        focusSort: function(postID){
        	this.cPostid = postID;
        	this.cSort = E.trim($('#sort_' + postID).val())
        },

        //修改分类排序
        editSort: function(postID, cityID){
        	if (!E.isInt(postID) || !E.isInt(cityID)) {
        		E.alert('参数错误，请刷新页面后重新操作');
        		return false;
        	}

        	var sortOrder = E.trim($('#sort_' + postID).val());
        	if (!E.isInt(sortOrder)) {
        		E.alert('参数错误，请刷新页面后重新操作');
        		return false;
        	}

        	E.ajax_post({
        		url: "/invokingAjax-backend/goods/goodsSale.ajax?operFlg=4",
        		data: {
        			postID: postID,
        			sortOrder: sortOrder,
        			cityID: cityID
        		},
        		call: 'goods.sortCall'
        	});
        },

        sortCall: function(o){
        	if (o.code != 200) {
        		E.alert(o.message);
        		$('#sort_' + this.cPostid).val(this.cSort)
        	}
        },

        //基本信息编辑
        listEdit: function(postID){
            self.location = '/quanliadmin/app/goods/goodsSale.pscript?operFlg=2&postID='+postID;
        },

        //sku信息编辑
        skuEdit: function(postID){
            self.location = '/quanliadmin/app/goods/goodsSale.pscript?operFlg=3&postID='+postID;
        },

        //图片编辑
        picEdit: function(postID){
            self.location = '/quanliadmin/app/goods/goodsSale.pscript?operFlg=5&postID='+postID;
        },

        //生产信息编辑
        productEdit: function(postID){
            self.location = '/quanliadmin/app/goods/goodsSale.pscript?operFlg=4&postID='+postID;
        }

    };
</script>
</body>
</html>